home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
015
/
printset.arc
/
PRINTSET.C
< prev
next >
Wrap
C/C++ Source or Header
|
1985-08-13
|
18KB
|
475 lines
/* PRINTSET.C
Program to allow setup of printer special functions.
Copyright (c) 1985, Hawkeye PC Programmer's SIG
Revision History
03/26/85 Version 1.01 Added compiler run-time memory limitations
so the program doesn't overwrite command.com
in high RAM. Modified by Gordon Waite.
Changed exit: if invoked with complete comm
line, no exit messages are printed. Suggested
by Bob Bryla. Modified by Gordon Waite.
Revised the DELETE key routine during integer
entry. Changed case where cursor is in last
position. Modified by Gordon Waite.
Changed CHOICES to CHOICE in commands menu.
Modified by Gordon Waite.
07/11/85 Version 1.02 Added color attributes for C/G users.
Added the /b option to force monochrome.
07/14/85 Version 1.03 Fixed two printer setups by replacing
upper case IBM's to lower case. This was
needed to work with the parser forcing
command line arguments to lower case prior
to parsing. Modified by Gordon Waite.
Added a check after the shareware screen is
displayed to look for the user pressing the
ESC key. If that is done, the program will
now terminate instead of passing on to the
next stage. Modified by Gordon Waite.
08/08/85 Version 1.04 Fixed problems with the Gemini printer.
08/13/85 Version 1.05 Added oki100-ibm printer setup
This program was compiled using the Computer Innovations C-86 'C'
compiler, version 2.3, using the small memory model.
======================================================================= */
#define DEBUG 0 /* set to 0 when done with debugging, else 1 */
#include "printset.h"
#include "screen1" /* shareware & copyright notice */
#define MAXCOMMS 18 /* current number of possible commands */
#define MAXCUST 20 /* 20 chars is maximum custom setup string */
struct pstuff { /* definition of a printer data structure */
char *pname;
char *comms[MAXCOMMS];
};
#include "printers.c" /* actual printer definitions */
/* ================== External Function Declarations ===================== */
extern FILE *fopen();
extern int fclose();
extern char atcheck();
extern int crt_srcp(), dispmem(), equipmnt(), initcell();
extern int keystrok(), movescrn(), strlen();
extern int beep(), checker(), crt_srcp(), isdigit();
extern int readcls(), readcha(), to24(), writcho();
extern long atoi();
extern char *malloc(), *strcpy();
/* ================== Internal Function Declarations =================== */
int parsecom(), getname(), getcomm(), getout(), setup(), transpos(), usage();
int commhelp(), inint();
/* ========================= Global Variables ========================== */
int prntnumb; /* number of printer (name) found in command line */
int prntcomm[MAXCOMMS]; /* list of number of comm's found in command line */
int needprnt; /* if 1, no printer name was found in command line */
int needcomm; /* if 1, no direct commands were found in comm line */
char *dolist[MAXCOMMS]; /* the actual command list to be sent to the printer */
char custlist[MAXCUST]; /* custom setup array; filled in by user */
FILE *p; /* pointer to a file */
char *commname[] = { /* the codes used to identify specific commands */
/* an array of pointers to character strings */
"pi", /* pica */
"el", /* elite */
"co", /* compressed */
"pro", /* proportional spacing */
"exon", /* expanded print on */
"exoff", /* expanded print off */
"bon", /* boldface on */
"boff", /* boldface off */
"uon", /* underline on */
"uoff", /* underline off */
"norm", /* normal character set */
"alt1", /* alternate char set #1 */
"alt2", /* alternate char set #2 */
"gr", /* graphics char set */
"ff", /* form feed */
"1-6s", /* 1/6 inch line spacing */
"1-8s", /* 1/8 inch line spacing */
"reset", /* reset printer */
0 /* Null-terminate the list */
};
char *commdisp[] = { /* the names shown on menus */
"pica",
"elite",
"compressed",
"proportional spacing",
"expanded print on",
"expanded print off",
"boldface on",
"boldface off",
"underline on",
"underline off",
"normal character set",
"alternate character set #1",
"alternate character set #2",
"graphics character set",
"form feed",
"1/6 inch line spacing",
"1/8 inch line spacing",
"printer reset",
0 /* Null-terminate the list */
};
unsigned char *msg1 = "PRINTSET ver 1.05 (c) 1985, Hawkeye PC User Group, ALL RIGHTS RESERVED";
/* ======================================================================= */
/* M A I N L I N E */
/* ======================================================================= */
main(argc, argv)
int argc; /* number of command line arguments passed in */
char *argv[]; /* array of ptrs to the command line arguments */
{
int status; /* status returned from a function call */
equipmnt(); /* find out what equipment we're running on... */
if (!parsecom( argc, argv )) { /* process the command line */
/* if the returned status = 0, something is wrong! */
usage();
exit(1);
}
if (needprnt OR needcomm) /* display the shareware screen */
showshar();
if (needprnt) /* show a menu of printers */
if (!getname())
exit(1);
if (needcomm) /* show a menu of commands */
if (!getcomm())
exit(1);
transpos(); /* translate the command numbers into commands */
setup(); /* actually run out the printer setup codes */
if (needprnt OR needcomm) /* didn't use command line */
getout(1); /* exit from the program! */
}
/* ========================== End of Mainline ========================== */
/* ======================================================================= */
/* Internal Functions
/* ======================================================================= */
int usage() /* function which shows the user proper invocation of prog */
{
int i, j, k; /* loop variables */
char buff[21]; /* place to build an output line */
char buff2[11]; /* ditto */
char buff3[31]; /* ditto */
buff[20] = buff2[10] = buff3[30] = '\0';
puts("");
puts(msg1);
puts("");
puts("usage: printset [?] [/b] [printer name] [option list] [custom xx xx ... ]\n");
puts("where available printer names are:");
for (i = 0; printers[i].pname; i += 4) {
for (j = 0; j < 4 AND printers[i+j].pname; ++j) {
for (k = 0; k < 20; ++k)
if (k < strlen(printers[i+j].pname))
buff[k] = printers[i+j].pname[k];
else
buff[k] = ' ';
printf("%s", buff);
}
if (j != 4)
break;
}
printf("\n\nand options are:\n");
for (i = 0; commdisp[i]; i += 2) {
for (j = 0; j < 2 AND commdisp[i+j]; ++j) {
for (k = 0; k < 10; ++k)
if (k < strlen(commname[i+j]))
buff2[k] = commname[i+j][k];
else
buff2[k] = ' ';
printf("%s", buff2);
for (k = 0; k < 30; ++k)
if (k < strlen(commdisp[i+j]))
buff3[k] = commdisp[i+j][k];
else
buff3[k] = ' ';
printf("%s", buff3);
}
if (j != 2)
break;
}
printf("\nThe /b option stops color display for monochrome users with color cards.");
}
/* ....................................................................... */
int showshar() /* display the shareware notice */
{
int action; /* the user's keystroke */
movescrn( screen1, sizeof(screen1) );
atcheck( &scrn[1][4], 15, 15, 74 );
atcheck( &scrn[3][9], 15, 15, 69 );
dispmem( scrn );
crt_srcp( 25, 0, 0 ); /* send the cursor off page */
action = keystrok(); /* get any character from the keyboard */
if (action EQUALS ESC)
exit();
return;
}
/* ....................................................................... */
int getname() /* presents a menu of printer names to the user */
{
int answer; /* stores the user's reponse */
int i; /* loop variable */
int row, col; /* screen coordinates */
unsigned char buff[40]; /* a buffer to build a printer line */
int ok; /* is an entry OK? 1 = yes, 0 = no */
int retstat, retchar; /* used with inint() */
#if DEBUG
cls();
printf("Inside GETNAME\n\n");
keystrok();
#endif
initcell( &scrn[0][0], ' ', 7, 7 ); /* clear out the screen buff */
checker( &scrn[0][0], 15, 15, msg1 ); /* copyright message */
checker( &scrn[2][0], 7, 4, "List of possible printers:");
row = 5;
col = 5;
for (i = 0; printers[i].pname; ++i, ++row) { /* build the names list */
if (i != 0 AND i % 15 EQUALS 0) { /* new row */
row = 5;
col += 20;
}
sprintf(buff, "%2d. %s", i+1, printers[i].pname); /* build line */
checker( &scrn[row][col], 15, 15, buff ); /* update scrn buffer */
}
checker( &scrn[22][0], 15, 4,
"Please enter your choice [ESC to exit] ==>" );
ok = 0;
while (!ok) {
dispmem( scrn ); /* display the screen */
crt_srcp( 22, 46, 0 );
checker( &scrn[22][46], 7, 7, " ");
crt_srcp( 22, 46, 0 );
answer = inint( 2, " ", 1, &retstat, &retchar );
#if DEBUG
cls();
crt_srcp(0,0,0);
printf("The returned value of answer is %d.\n", answer);
printf("Values of RETSTAT = %d, RETCHAR = %d\n\n", retstat, retchar);
printf("I happens to be = %d\n", i);
keystrok();
#endif
if (retstat EQUALS 1) /* ESC was entered */
getout(0);
if (answer < 1 OR answer > i) {
beep();
}
else {
ok = 1;
}
}
prntnumb = answer - 1;
return(1); /* everything is OK */
}
/* ....................................................................... */
int getcomm() /* present a menu of possible printer commands */
{
int answer; /* stores the user's reponse */
int i; /* loop variable */
int row; /* screen coordinates */
unsigned char buff[40]; /* a buffer to build a printer line */
int ok; /* is an entry OK? 1 = yes, 0 = no */
int count; /* count of entered values */
int tcomms[MAXCOMMS]; /* temp array to hold status of settings */
int found; /* turned on when bad entry is found in list */
int numbcoms; /* number of possible commands */
int retstat, retchar; /* used with inint() */
#if DEBUG
cls();
printf("Inside GETCOMM\n\n");
keystrok();
#endif
for (i = 0; i < MAXCOMMS; ++i)
tcomms[i] = 0;
initcell( &scrn[0][0], ' ', 7, 7 ); /* clear out the screen buff */
checker( &scrn[0][0], 15, 15, msg1 ); /* copyright message */
checker( &scrn[2][0], 7, 4, "List of possible commands:");
row = 4;
for (i = 0; commname[i]; ++i, ++row) { /* build the comm names list */
sprintf(buff, "%2d. %s", i+1, commdisp[i] ); /* build line */
checker( &scrn[row][7], 15, 15, buff ); /* update scrn buffer */
}
numbcoms = i;
checker( &scrn[23][0], 15, 4,
"Please enter your choice ==>" );
commhelp();
count = 0;
answer = -1;
while (answer != 0 AND count < MAXCOMMS) { /* loop til a 0 is entered */
ok = 0;
while (!ok) { /* loop until user enters a valid number */
dispmem( scrn ); /* display the screen */
crt_srcp( 23, 31, 0 );
checker( &scrn[23][31], 7, 7, " " );
crt_srcp( 23, 31, 0 );
answer = inint( 2, " ", 1, &retstat, &retchar );
if (retstat EQUALS 1) /* ESC was entered */
getout(0);
if (answer < 0 OR answer > numbcoms)
beep();
else
ok = 1;
}
/* at this point, user has entered a valid number... */
/* process the answer, and if needed, go back for another entry */
if (answer != 0) {
if (tcomms[answer-1] EQUALS 1) {
/* if already entered, toggle it back off */
tcomms[answer-1] = 0;
found = 0;
for (i = 0; i <= count; ++i) {
if (found) {
prntcomm[i-1] = prntcomm[i];
}
else {
if (prntcomm[i] EQUALS answer-1) {
found = 1;
}
}
}
--count; /* fix the entry count */
checker( &scrn[answer + 3][5], 7, 7, " " ); /* fix fancy... */
}
else {
tcomms[answer-1] = 1; /* mark in our possible command list */
prntcomm[count++] = answer - 1; /* add command to our list */
checker( &scrn[answer + 3][5], 15, 14, "»" ); /* get fancy... */
}
}
}
if (count EQUALS 0) { /* user entered no commands... */
getout(0);
}
return(1); /* everything is OK */
}
/* ....................................................................... */
int commhelp() /* places additional help text on screen */
{
checker( &scrn[4][55], 15, 15, "INSTRUCTIONS");
atcheck( &scrn[4][55], 112, 112, 12);
checker( &scrn[6][44], 7, 1, "-- Type in option numbers, pressing");
checker( &scrn[7][44], 7, 1, " ENTER between each number.");
checker( &scrn[9][44], 7, 1, "-- Enter a zero (0) to complete the");
checker( &scrn[10][44], 7, 1, " setup.");
checker( &scrn[12][44], 7, 1, "-- Press the ESC key to cancel the");
checker( &scrn[13][44], 7, 1, " setup and exit the program.");
checker( &scrn[15][44], 7, 1, "-- Entering an option a second time");
checker( &scrn[16][44], 7, 1, " will cancel that option.");
}
/* ....................................................................... */
/* PARSECOM.C
This function is used to parse the command line passed into the
program PRINTSET. This function must accomplish three things:
1. If the user enters a printer name on the command line, PARSECOM
must take the name and check for its validity. If the printer
name is valid, the proper printer number is loaded into the
global variable PRNTNUMB. If no printer name is given in the
command line, parsecom must set the global variable NEEDPRNT
to zero (0) to ref